﻿Imports System.Windows.Controls.Primitives
Imports System.ComponentModel

Public Class EnvelopePhaseCurve
    Inherits Thumb

    Shared Sub New()
        DefaultStyleKeyProperty.OverrideMetadata(GetType(EnvelopePhaseCurve), New FrameworkPropertyMetadata(GetType(EnvelopePhaseCurve)))
    End Sub



    <Category("FMMatrix")> _
    Public Property Curve As Geometry
        Get
            Return DirectCast(GetValue(CurveProperty), Geometry)
        End Get
        Set(ByVal value As Geometry)
            SetValue(CurveProperty, value)
        End Set
    End Property

    Public Shared ReadOnly CurveProperty As DependencyProperty = DependencyProperty.Register( _
        "Curve", GetType(Geometry), GetType(EnvelopePhaseCurve), _
        New FrameworkPropertyMetadata(Nothing))



    <Category("FMMatrix")> _
    Public Property ClosedCurve As Geometry
        Get
            Return DirectCast(GetValue(ClosedCurveProperty), Geometry)
        End Get
        Set(ByVal value As Geometry)
            SetValue(ClosedCurveProperty, value)
        End Set
    End Property

    Public Shared ReadOnly ClosedCurveProperty As DependencyProperty = DependencyProperty.Register( _
        "ClosedCurve", GetType(Geometry), GetType(EnvelopePhaseCurve), _
        New FrameworkPropertyMetadata(Nothing))



    <Category("FMMatrix")> _
    Public Property Slope As Double
        Get
            Return DirectCast(GetValue(SlopeProperty), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(SlopeProperty, value)
        End Set
    End Property

    Public Shared ReadOnly SlopeProperty As DependencyProperty = DependencyProperty.Register( _
        "Slope", GetType(Double), GetType(EnvelopePhaseCurve), _
        New FrameworkPropertyMetadata(0.0))



    <Category("FMMatrix")> _
    Public Property Increment As Double
        Get
            Return DirectCast(GetValue(IncrementProperty), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(IncrementProperty, value)
        End Set
    End Property

    Public Shared ReadOnly IncrementProperty As DependencyProperty = DependencyProperty.Register( _
        "Increment", GetType(Double), GetType(EnvelopePhaseCurve),
        New FrameworkPropertyMetadata(1.0))



    Private origSlope As Double

    Private Sub EnvelopePhaseCurve_DragStarted(sender As Object, e As DragStartedEventArgs) Handles Me.DragStarted
        origSlope = Slope
    End Sub

    Private Sub EnvelopePhaseCurve_DragDelta(sender As Object, e As DragDeltaEventArgs) Handles Me.DragDelta
        Dim _slope = e.VerticalChange * Increment + origSlope
        If _slope > 5 Then _slope = 5
        If _slope < -5 Then _slope = -5
        Slope = _slope
    End Sub

End Class
